package Tests;

import java.util.Iterator;
import java.util.List;

import system.BlogSystem;
import bean.BlogBean;
import bean.CommentBean;
import bean.MediaBean;
import bean.PostBean;
import bean.UserBean;
import dao.BlogDAO;
import dao.CommentDAO;
import dao.DAO;
import dao.MediaDAO;
import dao.PostDAO;
import dao.UserDAO;

public class UserStoryFacade13 {

	private BlogSystem system = BlogSystem.getInstance();
	private DAO<UserBean> userDAO = UserDAO.getInstance(); 
	private DAO<BlogBean> blogDAO = BlogDAO.getInstance(); 

	private DAO<PostBean> postDAO = PostDAO.getInstance(); 
	private DAO<CommentBean> commentDAO = CommentDAO.getInstance();
	private DAO<MediaBean> mediaDAO = MediaDAO.getInstance(); 


	public void cleanPersistence() {

		Iterator<UserBean> users = userDAO.list().iterator();

		while(users.hasNext()){
			UserBean anotherUser = users.next();
			userDAO.delete(anotherUser);
		}

		Iterator<BlogBean> blogs = blogDAO.list().iterator();

		while(blogs.hasNext()){
			BlogBean anotherBlog = blogs.next();
			blogDAO.delete(anotherBlog);
		}

		Iterator<PostBean> posts = postDAO.list().iterator();

		while(blogs.hasNext()){
			PostBean post = posts.next();
			postDAO.delete(post);
		}

		Iterator<CommentBean> comments = commentDAO.list().iterator();

		while(comments.hasNext()){
			CommentBean comment = comments.next();
			commentDAO.delete(comment);
		}

		Iterator<MediaBean> medias = mediaDAO.list().iterator();

		while(medias.hasNext()){
			MediaBean media = medias.next();
			mediaDAO.delete(media);
		}

		system.finalize();

	}


	public void loadData(){

	}

	public String logon(String login, String senha) throws Exception {
		return system.login(login, senha);

	}

	public void createProfile(String login, String senha, String nome_exibicao,
			String email, String sexo, String dataNasc, String endereco,
			String interesses, String quem_sou_eu, String filmes,
			String musicas, String livros) throws Exception {

		system.createUser(login, senha, nome_exibicao, email, sexo, dataNasc,
				endereco, interesses, quem_sou_eu, filmes, musicas, livros);
	}


	public String createBlog(String sessionId, String title, String description) throws Exception{
		return system.createBlog(sessionId, title, description);
	}

	public String createPost(String sessionId, String blogId, String title,
			String text) throws Exception {
		return system.createPost(sessionId, blogId, title, text);

	}
	
	public String getNumberOfAnnouncements(String sessionId) throws Exception{
		return String.valueOf(system.getNumberOfAnnouncements(sessionId));
	}
	
	public void addPostAnnouncements(String sessionId, String blogId) throws Exception{
		system.addPostAnnouncements(sessionId, blogId);
	}
	
	public String getAnnouncement(String sessionId, int index) throws Exception{
		return system.getAnnouncement(sessionId, index);
	}
	
	public String getPostJustCreated(String announcementId){
		return system.getPostJustCreated(announcementId);
	}
	
	public void deleteAnnouncement(String sessionId, String announcementId) throws Exception{
		system.deleteAnnouncement(sessionId, announcementId);
	}



	public void logoff(String idSession) throws Exception{
		system.logout(idSession);
	}



	public void saveData(){

	}



}
